function sfscFormatter(val, row) {
	if (0 == val) {
		return "未删除";
	}
	if (1 == val) {
		return "已删除";
	}
}

function ctrlFormatter(val, row) {
	var oprate = "";
	oprate += "<div><a class='btn_blue06'  id='editbtn' onclick='javascript:editSelected("+ row.id + ")' href='javascript:void(0)'>绑定</a></div>";
	return oprate;
}

function editSelected(id) {
    if(id==null){
        $.messager.alert('提示', "请选择一条数据!", 'info');
        return;
    }
    
    $('#cityid').val(id);
    
    var $win;
	$win = $('#yhxxDetails').window({
	    title: '详情',
	    width: 520,
	    height: 450,
	    shadow: true,
	    modal: true,
	    closed: true,
	    minimizable: false,
	    maximizable: true,
	    maximized: true,  
	    collapsible: true
	});

	$win.window('open');
	
	/*$('#dgDetails').datagrid({
		height : backendCommon.getHeight(0.58),
		loadMsg : "数据装载中,请稍等....",
		url : mainDomain + '/gk/list.action',
		nowrap : false,
		rownumbers : true,
		fitColumns : false,
		pagination : true,
		singleSelect : false,
		pageSize : 10,
		pageNumber : 1,
		pageList : [ 10, 15, 20 ],
		columns : [ [{
			field : 'id',
			checkbox:true,
			width : $(this).width() * 0.05,
			align : 'center'
		},{
			field : 'gkmc',
			title : '港口',
			width : $(this).width() * 0.10,
			align : 'center'
		}] ]
	});*/
	
	$.ajax( {  
        type : 'POST',  
        url : mainDomain + '/gk/relist.action',  
        dataType:"json",
        data: 'cityid=' + id,
        success : function(data) {
        	if(data.length>0){
        		var rowcount = parseInt(data.length/10+1);
        		var info = '';
        		var t=0;
        		for(var i=0;i<rowcount;i++){
        			info += '<tr>';
        			for(j=t;j<t+10;j++){
        				if(data[j]!=null){
        					if(data[j].flag!=null){
            					info += '<td><input type="checkbox" name="flag" value='+ data[j].ID +' checked/>'+ data[j].GKMC +'</td>';
            				}else{
            					info += '<td><input type="checkbox" name="flag" value='+ data[j].ID +' />'+ data[j].GKMC +'</td>';
            				}
        				}	
        			}
        			info += '</tr>';
        			t+=10;
        		}
        		$('#dgDetails').html(info);
        	}
        },  
        error : function(data) {  
          console.log("失败");
        }  
      });
}

var names = [];
function tjSave() {
	names.splice(0,names.length);
	var cityid = $('#cityid').val();
	
	var chk_value =[];
	$('input[name="flag"]:checked').each(function(){ 
		chk_value.push($(this).val()); 
	}); 
	
	if(chk_value.length==0){
		$.messager.alert('提示', '至少选择一条记录', 'info');
		return;
	}
	
	$.each(chk_value, function(index, item){
		names.push({cityid: cityid,gkid: item,sfsc :0});
	});
	
	$.ajax( {  
        type : 'POST',  
        url : mainDomain + '/re/neworedit.action',  
        data : JSON.stringify(names),//将对象序列化成JSON字符串 
        dataType:"json",  
        contentType : 'application/json;charset=utf-8', //设置请求头信息 
        success : function(data) {
        	$.messager.alert('提示', '绑定成功', 'info');
        	$('#dgDetails').datagrid('reload');
        },  
        error : function(data) {  
          console.log("失败");
        }  
      });
}